import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ThrottlerModule } from '@nestjs/throttler';
import { AuthModule } from './auth/auth.module';
import { UserModule } from './user/user.module';
import { NovelModule } from './novel/novel.module';
import { CrawlerModule } from './crawler/crawler.module';
import { ShareModule } from './share/share.module';
import { CacheModule } from './cache/cache.module';
import { TestModule } from './test/test.module';

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      envFilePath: '.env',
    }),
    TypeOrmModule.forRoot({
      type: 'mysql',
      host: process.env.DB_HOST || 'localhost',
      port: parseInt(process.env.DB_PORT || '3306') || 3306,
      username: process.env.DB_USERNAME || 'root',
      password: process.env.DB_PASSWORD || '',
      database: process.env.DB_DATABASE || 'sbook',
      entities: [__dirname + '/**/*.entity{.ts,.js}'],
      synchronize: process.env.NODE_ENV !== 'production',
      dropSchema: process.env.NODE_ENV !== 'production',
    }),
    ThrottlerModule.forRoot([{
      ttl: 60000, // 1分钟
      limit: 10,  // 限制10次请求
    }]),
    CacheModule,
    AuthModule,
    UserModule,
    NovelModule,
    CrawlerModule,
    ShareModule,
    TestModule,
  ],
  controllers: [],
  providers: [],
})
export class AppModule {}
